require 'erb'
require 'common/base'

class HTTPBase < Base

  attr_accessor :step, :transport, :base_hosts, :base_options, :base_transports, :base_variables, :message, :url, :host, :content, :auth

  def initialize(step, filename, params = {}, transport="HTTP")
    super()
    @transport = transport
    @step = step
    
    @url = params["url"] or ""
    @host = params["host"] or ""
    @content = params["content"] or ""
    @auth = params["auth"] or ""

    @base_hosts ='&host_0 = host(role: "client", description: "client/src", type: v4)
        &host_1 = host(role: "server", description: "server/dst", type: v4)
   '
    
    @base_options = "
     $url = '<%= @url %>'
     $host = '<%= @host %>'
     $auth = '<%= @auth %>'
     $content = '<%= @content %>'"

    @base_variables = ''

    @base_transports = 'HTTP = tcp(src: &host_0, dst: &host_1, dst_port: 80)'

    if !filename.nil?
      template = get_message("HTTP", filename)
      erb = ERB.new(template, 0, '%<>')
      @message = erb.result(binding)
    end
  end
end

